<template>
  <div class="main">
    <div class="content">
      <el-form ref="form">
        <el-form-item label="金券号">
          <el-input v-model="voucherId"></el-input>
        </el-form-item>
        <el-form-item label="兑换码">
          <el-input v-model="voucherCode"></el-input>
        </el-form-item>
      </el-form>
      <div style="padding-top: 30px">
        <el-button class="button" type="primary" @click="tryToUse">兑换</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import cookie from "js-cookie";
import {useVoucher} from "@/http/api/voucher";

export default {
  name: "Voucher",
  data() {
    return {
      voucherId: '',
      voucherCode: '',
    }
  },
  methods: {
    async tryToUse(){
      let result = await useVoucher({
        userId: cookie.get('userId'),
        voucherId: this.voucherId,
        voucherCode: this.voucherCode,
      })
      if (result.code === 0) {
        this.$message.success('兑换成功')
      }else{
        this.$message.warning(result.message)
      }
    }
  }
}
</script>

<style scoped>

</style>